<?php
/**
 * member.class.php
 */

class member
{
	var $db;
	var $table;
	var $tablepre;
	var $_userid;
	
	function __construct()
	{
		global $db, $tablepre;
		$this->db = &$db;
		$this->table = $tablepre.'admin';
	}
	
	function member()
    {
    	$this->__construct();
    }
    
    function get($userid, $fields='*')
    {
    	$userid = intval($userid);
    	$sql = "SELECT $fields FROM `$this->table` WHERE id='$userid'";
    	return $this->db->result_first($sql);
    }
    
    function login($username, $password)
    {
    	if(!$this->member_exists('name', $username))
    	{
    		$this->msg = 'member_no_exists';
    		return false;
    	}
    	
    	$password_md5 = md5($password);
    	$this->_userid = $this->db->result_first("SELECT id FROM `$this->table` WHERE name='$username' and pass='$password_md5'");
    	if(!$this->_userid)
    	{
    		$this->msg = 'badpassword';
    		return false;
    	}
    	return $this->_userid;
    }
    
    function member_exists($field='name', $value)
    {
    	return $this->db->result_first("SELECT id FROM `$this->table` WHERE $field='$value' LIMIT 0,1");
    }
}
?>